package util.test.erp;

import java.text.MessageFormat;

import com.hm.common.util.DateUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2018年4月16日 下午4:19:47
 * @version 1.0
 * @describe
 */
@Slf4j
public class DriverMatEngine {

	@SuppressWarnings("incomplete-switch")
	private static DriverMatAssetsStatusEnum status(DriverMatAssetsRoleEnum matAssetsRole, DriverMatOpsEnum driverMatOps, DriverMatAssetsStatusEnum current) {
		// log.info("加载角色{},当前操作{}的下一个状态[当前数据状态为 {}]", matAssetsRole, driverMatOps,
		// current.desc());
		if (matAssetsRole == DriverMatAssetsRoleEnum.CAR_CAPTAIN) {
			switch (current) {
			case TO_AUDIT:
				switch (driverMatOps) {
				case REJECTED:
					return DriverMatAssetsStatusEnum.IN_DOUBT;
				case TERMINATION:
					return DriverMatAssetsStatusEnum.HAS_TERMINATION;
				case THROUGH:
					return DriverMatAssetsStatusEnum.TO_REPEAT_AUDIT;
				}
				break;
			case HAS_REJECTED:
				switch (driverMatOps) {
				case TERMINATION:
					return DriverMatAssetsStatusEnum.HAS_TERMINATION;
				case THROUGH:
					return DriverMatAssetsStatusEnum.TO_REPEAT_AUDIT;
				}
				break;
			case IN_DOUBT:
				switch (driverMatOps) {
				case TERMINATION:
					return DriverMatAssetsStatusEnum.HAS_TERMINATION;
				case THROUGH:
					return DriverMatAssetsStatusEnum.TO_REPEAT_AUDIT;
				}
				break;
			}
			
			throw new NullPointerException(MessageFormat.format("没找到角色{0},当前操作{1}的下一个状态[当前数据状态为 {2}]", matAssetsRole, driverMatOps, current.desc()));
		}

		// 财务
		switch (current) {
		case TO_ISSUE:
			if(driverMatOps == DriverMatOpsEnum.RELEASE) {
				return DriverMatAssetsStatusEnum.HAS_TO_ISSUE;
			}
			break;
		case TO_REPEAT_AUDIT:
			switch (driverMatOps) {
			case THROUGH:
				return DriverMatAssetsStatusEnum.TO_ISSUE;
			case REJECTED:
				return DriverMatAssetsStatusEnum.HAS_REJECTED;
			}
			break;
		}
		
		throw new NullPointerException(MessageFormat.format("没找到角色{0},当前操作{1}的下一个状态[当前数据状态为 {2}]", matAssetsRole, driverMatOps, current.desc()));
	}

	public static DriverMatAssetsStatusEnum next(DriverMatAssetsRoleEnum matAssetsRole, DriverMatOpsEnum driverMatOps, DriverMatAssetsStatusEnum current) {
		DriverMatAssetsStatusEnum nextStatus = status(matAssetsRole, driverMatOps, current);
		log.info("{}获取角色{},当前操作{}的,上一个状态是 [{}],下一个状态是 {}", DateUtil.now4yyyyMMddhhmm(), matAssetsRole, driverMatOps, current.desc(), nextStatus.desc());

		return nextStatus;
	}
}
